package lucene.news;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.queryparser.classic.QueryParser.Operator;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;

import lion.se.lucene.search.IQueryBuilder;
import lion.se.lucene.search.UserQueryFilter;

/**
 * @author lion
 * @email hl_0074@sina.com
 * @date 2014年4月15日
 */
public class NewsQueryBuilder implements IQueryBuilder {

	@Override
	public Query build(Analyzer analyzer) {

		BooleanQuery bq = new BooleanQuery();

		QueryParser qp = new QueryParser("title", analyzer);
		qp.setDefaultOperator(Operator.AND);
		Query q = null;
		try {
			q = qp.parse(UserQueryFilter.filter("*:*"));
			q.setBoost(10);
			bq.add(q, Occur.MUST);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		qp = new QueryParser("content", new StandardAnalyzer());
		try {
			q = qp.parse("(\"200\")");
			bq.add(q, Occur.MUST);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		System.out.println(bq.toString());

		return bq;
	}

	@Override
	public int getStart() {

		return 0;
	}

	@Override
	public int getSize() {

		return 0;
	}

	@Override
	public Sort getSort() {

		return null;
	}
}
